package com.example.fairplay.newfpregistration.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.fairplay.newfpregistration.R;
import com.example.mylibrary.data.StudentInfo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by fairplay on 2018/6/5.
 */

public class RecordDatasAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
	private List<StudentInfo> list;
	private Context mContext;

	public RecordDatasAdapter(Context mContext, List<StudentInfo> mList) {
		this.list = mList;
		this.mContext = mContext;

	}

	@Override
	public InfoViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		InfoViewHolder infoViewHolder = new InfoViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_list_view, parent, false));
		return infoViewHolder;
	}

	@Override
	public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
		holder.itemView.setTag(position + "");

		InfoViewHolder infoViewHolder = (InfoViewHolder) holder;

		infoViewHolder.textSex.setText(list.get(position).getSex() == 0 ? "男" : "女");
		infoViewHolder.textRollCallTime.setText(list.get(position).getFinalRollCalltime());
		infoViewHolder.textSendingState.setText(list.get(position).getUploadState() == 0 ? "未上传" : "已上传");
		int rollCallState = list.get(position).getRollCallState();
		if (rollCallState == 0) {
			infoViewHolder.textStateRollCall.setText("未检录");
		} else if (rollCallState == 1) {
			infoViewHolder.textStateRollCall.setText("通过");
		} else {
			infoViewHolder.textStateRollCall.setText("未通过");
		}
		infoViewHolder.textStuCode.setText(list.get(position).getStudenCode());
		infoViewHolder.textStuName.setText(list.get(position).getStudentName());
		infoViewHolder.textTrackNo.setText(position + 1 + "");
	}

	@Override
	public int getItemCount() {
		return list.size();
	}

	static class InfoViewHolder extends RecyclerView.ViewHolder {
		@Bind(R.id.tv_trackNo)
		TextView textTrackNo;
		@Bind(R.id.tv_studentCode)
		TextView textStuCode;
		@Bind(R.id.tv_studentName)
		TextView textStuName;
		@Bind(R.id.tv_sex)
		TextView textSex;
		@Bind(R.id.tv_state_rollcall)
		TextView textStateRollCall;
		@Bind(R.id.tv_rollcall_time)
		TextView textRollCallTime;
		@Bind(R.id.tv_sending_state)
		TextView textSendingState;

		View itemView;

		public InfoViewHolder(View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);
			this.itemView = itemView;
		}
	}
}
